<% Option Explicit %>
<!-- METADATA TYPE="typelib" FILE="C:\Program files\Common Files\System\ado\msado15.dll" -->
<!--#include virtual="/CreditCard/configuration.asp" -->
<!--#include virtual="/library/_dbTools.asp" -->
<!--#include virtual="/library/_Tools.asp" -->
<!--#include virtual="/creditcard/includes/_Tools.asp" -->
<!--#include virtual="/library/_Cookies.asp" -->
<script type="text/javascript" language="javascript" runat="server" src="/ajax/lang/extensions.js"></script>
<script type="text/javascript" language="javascript" runat="server" src="/ajax/net/ContentLoader.js"></script>
<script type="text/javascript" language="javascript" runat="server" src="/ajax/data/Serialization.js"></script>
<%
Dim adoCon, rsResult, strSQL
Dim message, cardType, method, dataRow, dataString
Set adoCon   = Server.CreateObject("ADODB.Connection")
Set rsResult = Server.CreateObject("ADODB.Recordset")
adoCon.Open getConnectionProperty("ssDevBAPS")

method = Request("Method")
dataString = Request("Data")
'dataString = "{PCardProfileID: 23, CardNumber: 'Kev', CardType: 'RBS'}"
'method="Update"


if method = "Update" Then      
    Set dataRow = ajax.lang.toJsonObject(dataString)
    if dataRow.PCardProfileID > 0 Then        
        ' Update
        strSQL  = "Update Baps_Reports..tbl_PCardProfiles Set " _
                & "CardNumber='" & Replace(dataRow.CardNumber, "'", "''") & "', " _
                & "CardType='"   & Replace(dataRow.CardType, "'", "''") & "' " _
                & "Where PCardProfileID=" & dataRow.PCardProfileID _
                & ";Select * from Baps_Reports..tbl_PCardProfiles Where PCardProfileID=" & dataRow.PCardProfileID
        
    Else        
        ' Insert
        strSQL  = "Insert Into Baps_Reports..tbl_PCardProfiles (CardNumber, CardType) Values (" _
                & "'" & Replace(dataRow.CardNumber, "'", "''") & "', " _
                & "'" & Replace(dataRow.CardType, "'", "''") & "'" _                
                & ");Select * from Baps_Reports..tbl_PCardProfiles Where PCardProfileID = Scope_Identity()"
       
    end If
ElseIf method = "Delete" Then
    Set dataRow = ajax.lang.toJsonObject(dataString)
    ' Delete    
    strSQL  = "Delete Baps_Reports..tbl_PCardProfiles Where PCardProfileID=" & dataRow.PCardProfileID & " " _
            & ";Select " & dataRow.PCardProfileID  & " as PCardProfileID, 'True' as RowDeleted"


Else
    ' Select    
    strSQL = "Select * from Baps_Reports..tbl_PCardProfiles Order By PCardProfileID"
End If


rsResult.Open strSQL, adoCon, 3, 1

' If not just a get data then set to 2nd recordset
if method <> "" Then Set rsResult = rsResult.NextRecordset
message = ajax.data.Serialization.xmlMessage(method, rsResult)
' Clean up
rsResult.Close

Set rsResult = Nothing
adoCon.Close
set adoCon = Nothing

' Output
Response.ContentType = "text/html"
call Response.Write(message) 
Call Response.End()   


%>